home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
JCSM Shareware Collection 1993 November
/
JCSM Shareware Collection - 1993-11.iso
/
cl720
/
qbscr2j.lzh
/
MAKEMENU.BAS
< prev
next >
Wrap
BASIC Source File
|
1992-07-08
|
18KB
|
399 lines
FUNCTION MakeMenu% (choice$(), numOfChoices%, justify$, leftColumn, rightColumn, row%, marker$, divider$, fg%, bg%, hfg%, hBG%, qfg%, qbg%, useMouse%)
'┌────────────────────────────────────────────────────────────────────────┐
'│ The MakeMenu function displays a menu list on the screen and allows │
'│ the user to move a scrolling selection bar to highlight the entry of │
'│ their choice. Selection is made by hitting the ENTER key. Other │
'│ allowable keys include Home or PgUp to move to the first menu entry, │
'│ and End or PgDn to move to the last entry. Scroll bar wraps from top │
'│ to bottom and bottom to top. The function returns as a value the │
'│ position of the entry in the list of the user's selection. For ex- │
'│ ample, if the user selected the third item in a list of eight, the │
'│ function would return a value of three. Parameters for this function │
'│ are: │
'│ │
'│ choice$() - An array of strings that contains the actual menu │
'│ entries. Example: Choice$(1) = 'Menu selcection 1'. │
'│ Strings must be 78 characters or less in length. │
'│ numOfChoices% - The number of menu choices available. The same as │
'│ the number of elements in Choices$(). Allowable │
'│ range is 1 through 25. │
'│ justify$ - This string will contain a single letter, either an L, C, │
'│ or a R. L means left-justify the menu entries. C means │
'│ center them with respect to the left and right sides of │
'│ the menu (see LeftColumn and RightColumn parameters below) │
'│ and an R means right-justify the menu entries. │
'│ leftColumn - A numerical value containing the left-most column on │
'│ which menu entries will be displayed. Allowable range │
'│ is 1 though 76. │
'│ rightColumn - A numerical value containing the right-most column on │
'│ which menu entries will be displayed. Allowable range │
'│ is 5 through 80. │
'│ row% - A numerical value containing the first row on which to display │
'│ menu entries. Allowable range is 1 through 24. │
'│ marker$ - The character used in the menu entry strings that indicates │
'│ the next character is a 'Quick Access' key. │
'│ divider$ - The character used as a menu entry if a dividing line is │
'│ desired.
'│ fg% - The foreground color of normal menu entries. Allowable range │
'│ is 0 to 15. │
'│ bg% - The background color of normal menu entries. Allowable range │
'│ is 0 to 7. │
'│ hfg% - The foreground color of the highlighted menu entry. Allowable │
'│ range is 0 to 15. │
'│ hbg% - The background color of the highlighted menu entry. Allowable │
'│ range is 0 to 7. │
'│ qfg% - The foreground color of the Quick Access keys. Allowable │
'│ range is 0 to 15. │
'│ qbg% - The background color of the Quick Access keys. Allowable │
'│ range is 0 to 7. │
'│ useMouse% - 1 = use mouse support, 0 = don't.
'└────────────────────────────────────────────────────────────────────────┘
'─────────────────────────────────────────────────────────────────────────
' Set local variables - extended scan codes for keypad keys
'─────────────────────────────────────────────────────────────────────────
up$ = CHR$(0) + CHR$(72)
down$ = CHR$(0) + CHR$(80)
enter$ = CHR$(13)
home$ = CHR$(0) + CHR$(71)
EndKee$ = CHR$(0) + CHR$(79)
PgUpKey$ = CHR$(0) + CHR$(73)
PgDnKey$ = CHR$(0) + CHR$(81)
esc$ = CHR$(27)
'─────────────────────────────────────────────────────────────────────────
' Define other local variables.
'─────────────────────────────────────────────────────────────────────────
mx% = 0
my% = 0
lmCnt% = 0
rmCnt% = 0
returnIt% = FALSE
updateMenu% = FALSE
'─────────────────────────────────────────────────────────────────────────
' Define the error tone string to use with PLAY
'─────────────────────────────────────────────────────────────────────────
errorTone$ = "MB T120 L50 O3 AF"
'─────────────────────────────────────────────────────────────────────────
' Set type of justification to uppercase
'─────────────────────────────────────────────────────────────────────────
justify$ = UCASE$(justify$)
wdth% = (rightColumn - leftColumn - 1)
'─────────────────────────────────────────────────────────────────────────
' Check for out-of-bounds parameters. If any are out of range,
' quit the function
'─────────────────────────────────────────────────────────────────────────
IF numOfChoices% < 1 OR numOfChoices% > 25 THEN EXIT FUNCTION
IF justify$ <> "C" AND justify$ <> "L" AND justify$ <> "R" THEN EXIT FUNCTION
IF leftColumn < 1 OR rightColumn > 80 THEN EXIT FUNCTION
IF row% < 1 OR row% > 24 THEN EXIT FUNCTION
'─────────────────────────────────────────────────────────────────────────
' Calculate the array of character identifiers
'─────────────────────────────────────────────────────────────────────────
REDIM charID(numOfChoices%) AS STRING * 1
FOR x% = 1 TO numOfChoices%
FOR y% = 1 TO LEN(choice$(x%))
IF MID$(choice$(x%), y%, 1) = marker$ THEN
charID(x%) = UCASE$(MID$(choice$(x%), y% + 1, 1))
EXIT FOR
END IF
NEXT y%
NEXT x%
'─────────────────────────────────────────────────────────────────────────
' Calculate length of longest menu choice and store value in ChoiceLen%
'─────────────────────────────────────────────────────────────────────────
choiceLen% = 0
FOR x% = 1 TO numOfChoices%
IF LEN(choice$(x%)) > choiceLen% THEN
IF INSTR(choice$(x%), marker$) THEN
choiceLen% = LEN(choice$(x%))
ELSE
choiceLen% = LEN(choice$(x%)) + 1
END IF
END IF
NEXT x%
choiceLen% = choiceLen% - 1
'─────────────────────────────────────────────────────────────────────────
' Determine left-most column to display highlight bar on
'─────────────────────────────────────────────────────────────────────────
col = (((rightColumn - leftColumn - 1) - choiceLen%) / 2) + leftColumn
'─────────────────────────────────────────────────────────────────────────
' At this point, we must turn off the mouse cursor if it's available. We
' don't want to write overtop of it, leaving a hole when it's moved later.
'─────────────────────────────────────────────────────────────────────────
IF useMouse% THEN
MouseHide
END IF
'─────────────────────────────────────────────────────────────────────────
' Print menu choices to screen based on the type of Justification
' selected (Center, Left, Right).
'─────────────────────────────────────────────────────────────────────────
COLOR fg%, bg%
SELECT CASE justify$
CASE "C"
FOR x% = 1 TO numOfChoices%
xCol% = ((wdth% - (LEN(choice$(x%))) - 1) \ 2 + leftColumn) + 1
LOCATE (row% - 1) + x%, leftColumn - 1, 0
PRINT SPACE$(choiceLen% + 2);
LOCATE (row% - 1) + x%, xCol%, 0
DisplayEntry choice$(x%), qfg%, qbg%, hfg%, hBG%, fg%, bg%, marker$, divider$, wdth%, 1
NEXT x%
CASE "R"
FOR x% = 1 TO numOfChoices%
LOCATE (row% - 1) + x%, leftColumn - 1, 0
PRINT SPACE$(choiceLen% + 2);
LOCATE (row% - 1) + x%, (rightColumn - LEN(choice$(x%)))
DisplayEntry choice$(x%), qfg%, qbg%, hfg%, hBG%, fg%, bg%, marker$, divider$, wdth%, 1
NEXT x%
CASE "L"
FOR x% = 1 TO numOfChoices%
LOCATE (row% - 1) + x%, leftColumn - 1, 0
PRINT SPACE$(choiceLen% + 2);
LOCATE (row% - 1) + x%, leftColumn, 0
DisplayEntry choice$(x%), qfg%, qbg%, hfg%, hBG%, fg%, bg%, marker$, divider$, wdth%, 1
NEXT x%
END SELECT
'─────────────────────────────────────────────────────────────────────────
' Highlight the first entry in the list. Must take into account the
' justification type.
'─────────────────────────────────────────────────────────────────────────
currentLocation% = 1
oldLocation% = 1
COLOR hfg%, hBG%
LOCATE row%, leftColumn - 1: PRINT SPACE$(choiceLen% + 2);
SELECT CASE justify$
CASE "C"
xCol% = ((wdth% - (LEN(choice$(currentLocation%))) - 1) \ 2 + leftColumn) + 1
LOCATE (row% - 1 + currentLocation%), xCol%, 0
DisplayEntry choice$(currentLocation%), qfg%, qbg%, hfg%, hBG%, fg%, bg%, marker$, divider$, wdth%, 2
CASE "R"
LOCATE (row% - 1) + currentLocation%, (rightColumn - LEN(choice$(currentLocation%)))
DisplayEntry choice$(currentLocation%), qfg%, qbg%, hfg%, hBG%, fg%, bg%, marker$, divider$, wdth%, 2
CASE "L"
LOCATE (row% - 1) + currentLocation%, leftColumn
DisplayEntry choice$(currentLocation%), qfg%, qbg%, hfg%, hBG%, fg%, bg%, marker$, divider$, wdth%, 2
END SELECT
'─────────────────────────────────────────────────────────────────────────
' Read keystrokes and change the highlighted entry appropriately. Also
' drain out any pending mouse button presses if the mouse is available.
'─────────────────────────────────────────────────────────────────────────
exitCode% = FALSE
IF useMouse% THEN
MouseButtonPressInfo LEFTBUTTON, lmCnt%, mx%, my%
MouseButtonPressInfo RIGHTBUTTON, rmCnt%, mx%, my%
lmCnt% = 0
rmCnt% = 0
END IF
WHILE exitCode% = FALSE
'─────────────────────────────────────────────────────────────────────
' If we're using the mouse, turn it on.
'─────────────────────────────────────────────────────────────────────
IF useMouse% THEN
MouseShow
END IF
'─────────────────────────────────────────────────────────────────────
' Read keystrokes and/or mouse presses.
'─────────────────────────────────────────────────────────────────────
key$ = ""
lmCnt% = 0
rmCnt% = 0
IF useMouse% THEN
MouseButtonPressInfo RIGHTBUTTON, rmCnt%, mx%, my%
MouseButtonPressInfo LEFTBUTTON, lmCnt%, mx%, my%
'───────────────────────────────────────────────────────────────────
' Did we have any left mouse button presses? If not, check the
' keyboard for input.
'───────────────────────────────────────────────────────────────────
IF lmCnt% = 0 THEN
key$ = UCASE$(INKEY$)
END IF
ELSE
'───────────────────────────────────────────────────────────────────
' No mouse available, so wait for keyboard input.
'───────────────────────────────────────────────────────────────────
WHILE key$ = ""
key$ = UCASE$(INKEY$)
WEND
END IF
'─────────────────────────────────────────────────────────────────────
' If the left mouse button was pressed, check to see if a menu item
' was selected by it.
'─────────────────────────────────────────────────────────────────────
IF (useMouse%) AND (lmCnt% > 0) THEN
'───────────────────────────────────────────────────────────────────
' Convert virtual screen mouse coordinates to real 80x25 coords.
'───────────────────────────────────────────────────────────────────
mx% = (mx% \ 8) + 1
my% = (my% \ 8) + 1
'───────────────────────────────────────────────────────────────────
' If mouse was inside menu window then return the item pointed to.
'───────────────────────────────────────────────────────────────────
IF (mx% >= leftColumn) AND (mx% <= rightColumn) AND (my% >= row%) AND (my% <= row% + numOfChoices% - 1) THEN
IF (choice$(my% - row% + 1) <> divider$) THEN
exitCode% = TRUE
updateMenu% = TRUE
currentLocation% = my% - row% + 1
key$ = charID(currentLocation%)
returnIt% = TRUE
END IF
END IF
END IF
'─────────────────────────────────────────────────────────────────────
' If right mouse button was pressed, then exit as if ESC were pressed.
'─────────────────────────────────────────────────────────────────────
IF (useMouse%) AND (rmCnt% > 0) THEN
MakeMenu% = 0
EXIT FUNCTION
END IF
'───────────────────────────────────────────────────────────────────
' Update currentLocation based on what user did, key-wise.
'───────────────────────────────────────────────────────────────────
SELECT CASE key$
CASE up$
IF currentLocation% > 1 THEN
currentLocation% = currentLocation% - 1
IF (choice$(currentLocation%) = divider$) AND (currentLocation% > 0) THEN
currentLocation% = currentLocation% - 1
END IF
ELSE
currentLocation% = numOfChoices%
END IF
updateMenu% = TRUE
CASE down$
IF currentLocation% < numOfChoices% THEN
currentLocation% = currentLocation% + 1
IF (choice$(currentLocation%) = divider$) AND (currentLocation% < numOfChoices%) THEN
currentLocation% = currentLocation% + 1
END IF
ELSE
currentLocation% = 1
END IF
updateMenu% = TRUE
CASE home$, PgUpKey$
IF currentLocation% <> 1 THEN
currentLocation% = 1
updateMenu% = TRUE
END IF
CASE EndKee$, PgDnKey$
IF currentLocation% <> numOfChoices% THEN
currentLocation% = numOfChoices%
updateMenu% = TRUE
END IF
CASE enter$
MakeMenu% = currentLocation%
exitCode% = TRUE
CASE esc$
MakeMenu% = 0
exitCode% = TRUE
CASE ELSE
'───────────────────────────────────────────────────────────────────
' Check quick access keys.
'───────────────────────────────────────────────────────────────────
FOR i% = 1 TO numOfChoices%
IF charID(i%) = key$ THEN
currentLocation% = i%
updateMenu% = TRUE
MakeMenu% = i%
exitCode% = TRUE
END IF
NEXT i%
END SELECT
'───────────────────────────────────────────────────────────────────
' If required, update the display.
'───────────────────────────────────────────────────────────────────
IF updateMenu% THEN
'───────────────────────────────────────────────────────────────────
' If mouse is around, turn it off, since we'll be displaying.
'───────────────────────────────────────────────────────────────────
IF useMouse% THEN
MouseHide
END IF
'─────────────────────────────────────────────────────────────────
' Restore the old highlighted item to normal colors.
'─────────────────────────────────────────────────────────────────
COLOR fg%, bg%
LOCATE row% + oldLocation% - 1, leftColumn - 1: PRINT SPACE$(choiceLen% + 2);
SELECT CASE justify$
CASE "C"
xCol% = ((wdth% - (LEN(choice$(oldLocation%))) - 1) \ 2 + leftColumn) + 1
LOCATE (row% - 1 + oldLocation%), xCol%, 0
DisplayEntry choice$(oldLocation%), qfg%, qbg%, hfg%, hBG%, fg%, bg%, marker$, divider$, wdth%, 1
CASE "R"
LOCATE (row% - 1) + oldLocation%, (rightColumn - LEN(choice$(oldLocation%)))
DisplayEntry choice$(oldLocation%), qfg%, qbg%, hfg%, hBG%, fg%, bg%, marker$, divider$, wdth%, 1
CASE "L"
LOCATE (row% - 1) + oldLocation%, leftColumn
DisplayEntry choice$(oldLocation%), qfg%, qbg%, hfg%, hBG%, fg%, bg%, marker$, divider$, wdth%, 1
END SELECT
'─────────────────────────────────────────────────────────────────
' Display newly highlighted item in highlight colors.
'─────────────────────────────────────────────────────────────────
COLOR hfg%, hBG%
LOCATE row% + currentLocation% - 1, leftColumn - 1: PRINT SPACE$(choiceLen% + 2);
SELECT CASE justify$
CASE "C"
xCol% = ((wdth% - (LEN(choice$(currentLocation%))) - 1) \ 2 + leftColumn) + 1
LOCATE (row% - 1 + currentLocation%), xCol%, 0
DisplayEntry choice$(currentLocation%), qfg%, qbg%, hfg%, hBG%, fg%, bg%, marker$, divider$, wdth%, 2
CASE "R"
LOCATE (row% - 1) + currentLocation%, (rightColumn - LEN(choice$(currentLocation%)))
DisplayEntry choice$(currentLocation%), qfg%, qbg%, hfg%, hBG%, fg%, bg%, marker$, divider$, wdth%, 2
CASE "L"
LOCATE (row% - 1) + currentLocation%, leftColumn
DisplayEntry choice$(currentLocation%), qfg%, qbg%, hfg%, hBG%, fg%, bg%, marker$, divider$, wdth%, 2
END SELECT
'─────────────────────────────────────────────────────────────────
' Reset old location to current.
'─────────────────────────────────────────────────────────────────
oldLocation% = currentLocation%
updateMenu% = FALSE
END IF
'───────────────────────────────────────────────────────────────────
' If the mouse was used to click on a menu choice, then return it
' and exit now.
'───────────────────────────────────────────────────────────────────
IF returnIt% THEN
MakeMenu% = currentLocation%
EXIT FUNCTION
END IF
WEND
END FUNCTION